package Homework;

public class MyThread {
    private boolean flag = false;

    //flag为true，主线程执行
    public synchronized void fu() {
        while (false == flag) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + i);
        }

        flag = false;
        notify();
    }

    //flag为false，子线程执行
    public synchronized void zi() {

        while (true == flag) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName() + i);
        }

        flag = true;
        notify();
    }
}
